package com.zkingsoft.codeApi;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.zkingsoft.generator.impl.DefaultNameConvert;

/**
 * 每一个codeFile 代表一个要生成的文件
 * 
 * @author Administrator
 *
 */
public class CodeFile {

	/**
	 * 导入类列表
	 */
	private Map<String, String> importList;

	/**
	 * 类的变量名称
	 */
	private String classVariableName;
	
	
	/**
	 * dao 接口位置
	 */
	private String daoInterfase;
	

	/**
	 * 注入名称
	 */
	private String injectionName;
	
	
	private Attribute attribute; 
	

	

	public String getDaoInterfase() {
		return daoInterfase;
	}


	public void setDaoInterfase(String daoInterfase) {
		this.daoInterfase = daoInterfase;
	}


	public Attribute getAttribute() {
		return attribute;
	}


	public void setAttribute(Attribute attribute) {
		this.attribute = attribute;
	}

	/**
	 * 接口列表
	 */
	private List<String> interfases;

	/**
	 * 系统常用变量
	 */
	private Variables variables;

	/**
	 * 表模型信息
	 */
	private TableClassModel tableClassModel;

	/**
	 * 模型文件信息
	 */
	private TemplateModel templateModel;

	/**
	 * 文件全名 包含后缀
	 */
	private String fileName;

	/**
	 * 简单文件名 不含后缀
	 */
	private String simpleFileName;

	private Configuration configuration;
	
	private String packName;

	public CodeFile() {
		this.importList = new HashMap<String, String>();
		this.interfases = new ArrayList<String>();
	}

	
	public String getInjectionName() {
		return injectionName;
	}

	public void setInjectionName(String injectionName) {
		this.injectionName = injectionName;
	}

	public String getFileName() {
		StringBuffer name = new StringBuffer();
		String prefix = getTemplateModel().getPrefix();
		String suffix = getTemplateModel().getSuffix();
		String extensionName = getTemplateModel().getExtensionName();
		if (prefix != null) {
			name.append(prefix);
		}
		if(".jsp".equals(extensionName)){
			name.append(this.getTableClassModel().getViewName());
		}else{
			name.append(this.getTableClassModel().getClassName());
		}
		if (suffix != null) {
			name.append(suffix);
		}
		name.append(extensionName);
		fileName = name.toString();
		return fileName;
	}

	public String getFileName(String view) {
		StringBuffer name = new StringBuffer();
		String prefix = getTemplateModel().getPrefix();
		String suffix = getTemplateModel().getSuffix();
		String extensionName = getTemplateModel().getExtensionName();
		if (prefix != null) {
			name.append(prefix);
		}
		name.append(this.getTableClassModel().getViewName());
		if (suffix != null) {
			name.append(suffix);
		}
		name.append(extensionName);
		fileName = name.toString();
		return fileName;
	}

	public String getSimpleFileName() {
		return getFileName().substring(0, getFileName().indexOf("."));
	}

	public void setSimpleFileName(String simpleFileName) {
		this.simpleFileName = simpleFileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public Configuration getConfiguration() {
		return configuration;
	}

	public void setConfiguration(Configuration configuration) {
		this.configuration = configuration;
	}

	
	public List<String> getInterfases() {
		return interfases;
	}

	public void setInterfases(List<String> interfases) {
		this.interfases = interfases;
	}

	public Variables getVariables() {
		return variables;
	}

	public void setVariables(Variables variables) {
		this.variables = variables;
	}

	public Map<String, String> getImportList() {
		return importList;
	}

	public void setImportList(Map<String, String> importList) {
		this.importList = importList;
	}

	public TableClassModel getTableClassModel() {
		return tableClassModel;
	}

	public void setTableClassModel(TableClassModel tableClassModel) {
		this.tableClassModel = tableClassModel;
	}

	public TemplateModel getTemplateModel() {
		return templateModel;
	}

	public void setTemplateModel(TemplateModel templateModel) {
		this.templateModel = templateModel;
	}

	public String getClassVariableName() {
		DefaultNameConvert format = new DefaultNameConvert();
		return format.classNameToVariableName(this.getSimpleFileName());
	}

	public void setClassVariableName(String classVariableName) {
		this.classVariableName = classVariableName;
	}


	public String getPackName() {
		return packName;
	}


	public void setPackName(String packName) {
		this.packName = packName;
	}

}
